﻿using Microsoft.EntityFrameworkCore;
using Model;
using System.Reflection;

namespace Dqs_DAL
{
    public class MyDbContext : DbContext
	{
		public DbSet<AdminInfo> Admins { get; set; }
		public DbSet<StudentInfo> Students { get; set; }
		public DbSet<TeacherInfo> Teachers { get; set; }
		public DbSet<ClassInfo> ClassInfos { get; set; }
		public DbSet<CourseInfo> CourseInfos { get; set; }
		public DbSet<SeatInfo> SeatInfos { get; set; }
        public DbSet<Question> Question { get; set; }
        public DbSet<QuestionReply> QuestionReply { get; set; }
		


        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
		{
            string connStr = "server=.;database=DqsDemo;uid=sa;password=123456;TrustServerCertificate=true";
            optionsBuilder.UseSqlServer(connStr);
		}

		protected override void OnModelCreating(ModelBuilder modelBuilder)
		{
			base.OnModelCreating(modelBuilder);
			//modelBuilder.ApplyConfigurationsFromAssembly(this.GetType().Assembly);
			var assembly = Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Model.dll"));
			var types = assembly.GetTypes();
			foreach (var type in types)
			{
				modelBuilder.ApplyConfigurationsFromAssembly(type.Assembly);
			}
		}
	}
}
